package cn.com.ddapp.ddm.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.com.ddapp.ddm.R;
import cn.com.ddapp.ddm.api.OKUtilAPI;
import cn.com.ddapp.ddm.bean.HomeBean;

/**
 * Created by Administrator on 2016/8/31 0031.
 */
public class GoodsLandAdapter extends BaseAdapter {
    private Context context;
    private List<HomeBean.SortListBean> sortListBeen;

    public GoodsLandAdapter(Context context, List<HomeBean.SortListBean> sortListBeen) {
        this.context = context;
        this.sortListBeen = sortListBeen;
    }

    @Override
    public int getCount() {
        return sortListBeen.size();
    }

    @Override
    public Object getItem(int i) {
        return sortListBeen.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder=null;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_land_good, viewGroup, false);
            holder=new ViewHolder(view);
            view.setTag(holder);
        }else {
          holder= (ViewHolder) view.getTag();
        }
        Glide.with(context).load(OKUtilAPI.imgBaseUrl+sortListBeen.get(i).getImg()).into(holder.fenImage);
        holder.nameland.setText(sortListBeen.get(i).getName());

        return view;
    }

    class ViewHolder {
        @BindView(R.id.fenImage)
        ImageView fenImage;
        @BindView(R.id.nameland)
        TextView nameland;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
